package com.lemner.ke.fragment;

import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.lemner.ke.R;
import com.lemner.ke.adapter.KnowledageViewPageAdapter;
import com.lemner.ke.base.BaseFragment;
import com.lemner.ke.util.SeeMoreListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 知
 *
 * @author raintea
 * @date 2018/9/18
 */
public class KnowledgeFragment extends BaseFragment {

    TabLayout tabLKnow;
    ViewPager viewPagerKnow;
    private KnowledageViewPageAdapter knowledageViewPageAdapter;
    SeeMoreListener listener;

    public static KnowledgeFragment getInstance() {
        return new KnowledgeFragment();
    }

    public void setListener(SeeMoreListener listener){
        this.listener=listener;
    }

    @Override
    public int getLayoutFile() {
        return R.layout.fragment_knowledge;
    }

    @Override
    public void initSetting() {

    }

    @Override
    public void initView() {
        tabLKnow = findViewById(R.id.tl_knowledge);
        viewPagerKnow = findViewById(R.id.vp_knowledge);
    }

    @Override
    public void initEvent() {
        List<Fragment> fragmentList = new ArrayList<>();
        RecommendFragment recommendFragment = RecommendFragment.getInstance();
        recommendFragment.setMoreListener(listener);
        fragmentList.add(recommendFragment);
        fragmentList.add(VideoFragment.getInstance());

        List<String> titles = new ArrayList<>();
        titles.add("推荐");
        titles.add("视频");

        knowledageViewPageAdapter = new KnowledageViewPageAdapter(getChildFragmentManager());
        knowledageViewPageAdapter.setFragments(fragmentList, titles);
        viewPagerKnow.setAdapter(knowledageViewPageAdapter);

        tabLKnow.setTabMode(TabLayout.MODE_SCROLLABLE);
        tabLKnow.setSelectedTabIndicatorColor(Color.WHITE);
        tabLKnow.setSelectedTabIndicatorHeight(0);
        tabLKnow.setupWithViewPager(viewPagerKnow);

        for (int i = 0; i < tabLKnow.getTabCount(); i++) {
            TabLayout.Tab tabAt = tabLKnow.getTabAt(i);
            if (tabAt != null) {
                switch (i) {
                    case 0:
                        tabAt.setCustomView(R.layout.tablayout_tab_recommend);
                        break;
                    case 1:
                        tabAt.setCustomView(R.layout.tablayout_tab_video);
                        break;
                    default:
                }
            }

        }

    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View v) {

    }
}
